import com.intellij.openapi.components.Service
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import org.jdom.Element
import com.intellij.openapi.application.ApplicationManager
import com.intellij.util.xmlb.annotations.Attribute

@State(
    name = "GitBashSettings",
    storages = [Storage("GitBashSettings.xml")]
)
@Service(Service.Level.APP)
class GitBashSettings : PersistentStateComponent<Element> {
    @Attribute
    var gitBashPath: String = "C:\\Program Files\\Git\\git-bash.exe"  // 默认值

    override fun getState(): Element {
        return Element("settings").apply {
            setAttribute("gitBashPath", gitBashPath)
        }
    }

    override fun loadState(state: Element) {
        state.getAttributeValue("gitBashPath")?.let {
            gitBashPath = it
        }
    }

    companion object {
        val instance: GitBashSettings
            get() = ApplicationManager.getApplication().getService(GitBashSettings::class.java)
    }
}